import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

@WebServlet("/MainPage")
public class MainPage extends HttpServlet{
	
	public void doGet(HttpServletRequest hsreq,HttpServletResponse hsresp)throws ServletException,IOException{
		checkUser(hsreq.getSession(),hsresp);
		hsresp.setContentType("text/html");
		
		PrintWriter pw=hsresp.getWriter();
		//-------------end of read data
		
		pw.println("<html><body bgcolor=pink><center>");
		pw.println("<h1>Welcome to the Banking System, <br>"+hsreq.getSession().getAttribute("user")+" ! </h1><br><a href=Login?action=Logout>Logout</a>");
		pw.println("</center></body></hmtl>");
		pw.println("<form action=BankingServlet method=\"POST\"><input type=\"submit\" value=\"Go to View All Accounts Page\"/><input type=\"hidden\" name=\"View\" value=\"View\" /></form><br>");
		pw.println("<form action=\"Transfer.jsp\"><input type=\"submit\" value=\"Go to Transfer Money Page\"/></form><br>");
		pw.println("<form action=\"AddAccount.jsp\"><input type=\"submit\" value=\"Go to Add Account Page\"/></form><br>");
		pw.println("<form action=\"DeleteAccnt.jsp\"><input type=\"submit\" value=\"Go to Delete Account Page\"/></form><br>");
		pw.println("<form action=\"FreezeAccount.jsp\"><input type=\"submit\" value=\"Go to Freeze Account Page\"/></form><br>");
		pw.close();
	}

	
	void checkUser(HttpSession pSession, HttpServletResponse hsresp)throws ServletException,IOException{
		if (pSession.getAttribute("user")==null || ((String)pSession.getAttribute("user")).trim().equals("")){
			hsresp.sendRedirect("Login");
		}
	}
}